<template>
	<view class="homework">
		<view class="item-left">
			<view>{{item.title}}</view>
			<view v-if="item.status!='3'" class="item-time">截止时间：{{endTime}}</view>
		</view>
		<view class="item-status" @click="itemClick">
			<text v-if="item.status=='0'" class="item-status-exam">开始测评</text>
			<text v-else-if="item.status=='3'" class="item-status-look">查看</text>
			<text v-else-if="item.status=='4'" class="item-status-end">已结束</text>
			<text v-else-if="item.status=='1'" class="item-status-report">报告/解析</text>
		</view>
	</view>
</template>

<script>
	import {showToast,formatDate2} from '@/utils/index.js'
	export default {
		props: {
			index:{
				type:Object,
				default(){
					return {}
				}
			},
			item: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return{}
		},
		computed:{
			endTime(){
				return formatDate2(this.item.endTime)
			}
		},
		methods: {
			itemClick() {
				const status = this.item.status;
				if (status == '2') {
					this.$emit('showDialog',this.item.publishTime);
					return;
				}
				if (status == '0') {
					this.$emit('updateIndex',this.index)
					uni.navigateTo({
						url:`/pages/homework/index?lessonId=${this.item.lessonId}`
					})
				} else if (status == '1') {
					uni.navigateTo({
						url:`/pages/homework/result?lessonId=${this.item.lessonId}`
					})
				} else if (status == '3') {
					uni.navigateTo({
						url: `/pages/course/offlineHomework?lessonId=${this.item.lessonId}`
					})
				} else if (status == '4') {
					showToast("超过截止时间啦～")
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.homework {
		background-color: #f7f7f7;
		border-radius: 8upx;
		padding: 20upx;
		margin-left: 60upx;
		display: flex;
		align-items: center;
		margin-top: 20upx;
	}

	.item-left {
		flex: 1;
		font-size: 24upx;
		color: #333333;
	}

	.item-time {
		font-size: 20upx;
		margin-top: 20upx;
		color: #999999;
	}

	.item-status {
		font-size: 24upx;
		background: #4da1ff;
		color: #fff;
		width: 175upx;
		height: 55upx;
		line-height: 55upx;
		border-radius: 6upx;
		text-align: center;
	}
</style>
